class SceneIndex extends eui.Component implements eui.UIComponent {

	public sc_index: eui.Scroller;
	public gp_index: eui.Group;

	public constructor() {
		super();
	}


	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}

	protected childrenCreated(): void {
		super.childrenCreated();
		this.init()
	}

	private timeScale: number
	private frameFactor: number
	private totalFrames: number
	private totalPrgress: number
	private armatureDisplay: dragonBones.EgretArmatureDisplay

	private init() {
		this.timeScale = 2
		this.frameFactor = 6
		this.totalFrames = 4530
		this.totalPrgress = this.totalFrames * this.frameFactor * this.timeScale

		// scroller  关闭水平方向滚动
		this.sc_index.scrollPolicyH = eui.ScrollPolicy.OFF;
		this.sc_index.viewport.scrollV = 0.0001
		// eui.UIEvent.CHANGE "change"
		// debugger
		this.sc_index.addEventListener(eui.UIEvent.CHANGE, this.onScroll, this)
		this.sc_index.addEventListener( egret.TouchEvent.TOUCH_TAP,(e)=>{
			console.log(e)
			this.sc_index.viewport.scrollV+=10
		},this);

		this.initDragonBones()

		this.gp_index.addChild(this.armatureDisplay);
		this.armatureDisplay.x = 0;
		this.armatureDisplay.y = 0;

		this.setProgress(0)

	}

	private initDragonBones() {
		let egretFactory: dragonBones.EgretFactory = dragonBones.EgretFactory.factory
		let dragonbonesData = RES.getRes("main_ske_json")
		egretFactory.parseDragonBonesData(dragonbonesData)
		let textureData = {}, texture = {}

		for (let i = 0; i < 23; i++) {
			textureData = RES.getRes("main_tex_" + i + "_json")
			texture = RES.getRes("main_tex_" + i + "_png")
			egretFactory.parseTextureAtlasData(textureData, texture, "main")
		}
		this.armatureDisplay = egretFactory.buildArmatureDisplay("Armature")

	}

	private setProgress(rate = 0) {
		if (this.armatureDisplay) {
			this.armatureDisplay.animation.gotoAndStopByProgress("Animation", rate)
		}
	}

	private onScroll(e): void {
		// debugger
		console.log(this.sc_index.viewport.scrollV)
		this.setProgress(this.sc_index.viewport.scrollV / this.totalPrgress)
		this.sc_index.viewport.scrollV = this.sc_index.viewport.scrollV
	}

}